package com.ming.transaction.controller;

import com.ming.transaction.common.Result;
import com.ming.transaction.common.annotation.RecordLoggerAnnotation;
import com.ming.transaction.entity.Menu;
import com.ming.transaction.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
     *  菜单控制层
 * </p>
 *
 * @author 陈仕健
 * @since 2023-05-06
 */
@Api(tags = "菜单控制器")
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private IMenuService menuService;


    /**
     * 管理员手动添加菜单
     * @param menu
     * @return
     */
    @PostMapping
    @ApiOperation("管理员添加菜单")
    @RecordLoggerAnnotation(value = "管理员添加菜单")
    public Result save(@RequestBody Menu menu){
        return menuService.saveMenu(menu);
    }

    /**
     * 管理员修改菜单信息
     * @param menu
     * @return
     */
    @PutMapping
    @ApiOperation("管理员修改菜单")
    @RecordLoggerAnnotation(value = "管理员修改菜单")
    public Result editUser(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }

    /**
     * 管理员手动删除菜单
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("管理员删除菜单")
    @RecordLoggerAnnotation(value = "删除菜单")
    public Result delete(@PathVariable Integer id){
        return menuService.deleteById(id);
    }


    /**
     * 查询所有菜单 & 子菜单
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有菜单")
    public Result findAll(){
        return Result.success("查询所有菜单信息!",menuService.findAll());
    }


    /**
     * 批量删除菜单
     * @param ids
     * @return
     */
    @RecordLoggerAnnotation(value = "批量删除菜单")
    @ApiOperation("管理员批量删除菜单")
    @PostMapping("/del/batch")
    public Result deletebatch(@RequestBody List<Integer> ids) {
        return menuService.deleteByIds(ids);
    }

    /**
     * 查询图标
     * @return
     */
    @GetMapping("/icons")
    @ApiOperation("查询所有图标")
    public Result getIcons(){
        return Result.success("查询所有图标!",menuService.selectIcon());
    }
}

